package com.ethanzzh.ethanzzh_xdclass.utils;

import com.github.qcloudsms.SmsSenderUtil;

import java.util.Random;

import static com.github.qcloudsms.SmsSenderUtil.sha256;

public class SmsUtils {


    public static String calculateSignature(String appkey, long random, long time,
                                            String phoneNumber) {

        StringBuffer buffer = new StringBuffer("appkey=")
                .append(appkey)
                .append("&random=")
                .append(random)
                .append("&time=")
                .append(time)
                .append("&mobile=")
                .append(phoneNumber);

        return sha256(buffer.toString());
    }


    public static long getRandom() {
        return (new Random(SmsSenderUtil.getCurrentTime())).nextInt(900000) + 100000;
    }

    public static long getCurrentTime() {
        return System.currentTimeMillis() / 1000;
    }
}
